ref(pyreqwest): Move crumbs to integration - #7148
Conversation
Move subprocess breadcrumb creation from the centralized `maybe_create_breadcrumbs_from_span` hook into the stdlib integration's `Popen.__init__` wrapper. This makes breadcrumbs work for both legacy spans and streamed spans, and removes the dependency on span internals.
…-redis-breadcrumbs-to-integration
Codecov Results 📊✅ 111463 passed | ⏭️ 6749 skipped | Total: 118212 | Pass Rate: 94.29% | Execution Time: 404m 41s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 96.55%. Project has 2483 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.16% 90.20% +0.04%
==========================================
Files 193 193 —
Lines 25317 25337 +20
Branches 9280 9286 +6
==========================================
+ Hits 22827 22854 +27
- Misses 2490 2483 -7
- Partials 1427 1427 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e31a3aa. Configure here.
| from sentry_sdk.traces import StreamedSpan | ||
| from sentry_sdk.tracing import BAGGAGE_HEADER_NAME | ||
| from sentry_sdk.tracing_utils import ( | ||
| add_http_breadcrumb, |
There was a problem hiding this comment.
pyreqwest middleware skips breadcrumbs when HTTP requests raise exceptions
If next_handler.run(request) raises an exception (network error, timeout), the middleware skips breadcrumb creation because it only runs inside if response is not None:. The old fallback via Span.finish() and maybe_create_breadcrumbs_from_span no longer applies since tracing_utils.py now explicitly excludes pyreqwest ("auto.http.pyreqwest") from that path. As a result, connection-level failures produce no HTTP breadcrumb at all. Both sentry_async_middleware (~172) and sentry_sync_middleware (~217) share this flaw.
Evidence
sentry_async_middleware(line 172) andsentry_sync_middleware(line 217) setresponse = None, execute the request insidewith _sentry_pyreqwest_span(...), and only calladd_http_breadcrumbinsideif response is not None:after the block.- If
next_handler.run(request)raises, control jumps past the crumb code andresponsestaysNone. maybe_create_breadcrumbs_from_spanintracing_utils.py:228-246now skipsspan.origin == "auto.http.pyreqwest", so no fallback breadcrumb is recorded.StreamedSpan.__exit__marks the span as error but never creates a breadcrumb, and the oldSpan.finish()breadcrumb path is likewise blocked for this origin.- The new test suite (
test_pyreqwest.py) includes happy-path breadcrumb tests but no test simulating a connection-level exception.
Identified by Warden · find-bugs · CGK-YBX

Description
Create HTTP client breadcrumbs directly in the pyreqwest integration instead of using
maybe_create_breadcrumbs_from_span.Additionally:
Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)